#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>

using namespace std;

const int N = 2e5 + 10;

int T;
int n, ans;
int a[N];
map<int,int> mm;

int main()
{
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    scanf("%d", &T);
    while (T -- )
    {
        memset(a, 0, sizeof a);
        mm.clear();
        ans = 0;
        scanf("%d", &n);
        for (int i = 1; i <= n; i ++ )
        {
            scanf("%d", &a[i]);
            if (mm[a[i]] == 0)
            {
                mm[a[i]] ++ ;
            }
            else if (mm[a[i]])
            {
                mm[a[i]] ++ ;
                ans += a[i];
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}
